home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 49
/
Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso
/
-serious-
/
misc
/
football
/
exec
/
scheduler.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-11-29
|
23KB
|
775 lines
/* ***********************************************************************
SCHEDULER PROGRAM FOR FOOTBALL REXX SUITE
-------------------------------------------
Copyright Mark Naughton 1996
Version Date History
--------------------------------------------------------------------------
1.0 090996 First release.
180996 Changed record-count so that it is stored in element
zero of each array. Deleted some variable assigns
that weren't needed. Amended reading into arrays so
that the count is set correctly for one element.
Removed all "call "references before library routines.
270996 Added code to sort 'Teams.df' and to recreate it.
Changed a few messages and tidied up.
****** Decided not to store goalscorers. Was not viable as
too much data would have to be collected.
270996 Added code for points_per_draw and points_per_loss.
Now uses DOS Delete command, not the support function.
Amended reading in of teams - quicker, tidier. Added
code to display a report on the league. Updated to
use new filenames. Improved error messages. Added
error check for more than 1000 matches.
1.1 131196 Added argument so it can become a component of
FOOTBALL. Removed all messages. Added checks for
files - if not found, exits without a message.
Rewrote report.
201196 Added code to store relegation. All this will do is
display a line across the league table. Amended msg
for play_each_other. Added code to allow teams to
play each other more than twice.
201196 Decided not to implement PreviousPosition as it would
require file changes and a reformat of the league
table. It may be implemented soon though.
211196 Updated and tidied the display.
201296 Fixed bug where if the number of times that each team
play each other is an even number, then its not set
to the correct value (only works for odd matches).
110197 Blanks are now removed from the filename, before
creation.
1.2 110497 Added code to support Points_Per_Goals.
2.0 010997 Have been working on Scheduling for about a week. Put
in code and now ready to test.
030997 Problem with format of '.sf' file - fixed. Program
failed due to missing 'do' - fixed. All works.
050997 Added extra '*' at end of '.sf' file in line with
manual created one.
070997 Fixed bug for AUTOSCHED - no. of matches in report was
wrong - needed to be reset before the loop.
220997 Added code for promotion and divisions.
240997 Removed all data such as teams count, points per win,
relegation etc, as they are already stored in '.df'.
250997 Wasn't creating the files - traced to resetting the
strings that were used to pick the number of divisions
and the divisions themselves, to the variables that
are used as the assignments/counters. Made amendments
to display of the report.
151297 Tidied display.
240898 Amended code that regenerates .df file as it was
adding two blank lines before the teams and causing
it to fail.
210499 Scheduler now tidies up previous files, ie. deleting
a '.sflearn' file from a previous league.
2.1 050599 Added code to check the schedule file to see if it
contains enough matches for the league to be played
with the specified settings. Added support for playing
teams an odd number of times and for schedules with
teams playing it each other more than twice.
Enhanced a few messages.
2.2 160699 Added code to support creation of '.stats' files. Fixed
bug where Scheduler wouldn't allow 4 teams, 6 matches
as it calculated it to 12 matches (World Cup) - amended
if the number of matches is half that 'meant' to be
played.
250899 Added error msg to file checks.
290899 Converted to use locale. Some error messages, before
reading the locale, will still be in English.
010999 Converted to use a global date format file.
190999 Changed directory for schedule file.
**************************************************************************
Procedure
---------
1. Check files exist.
2. Read 'Teams.df' and write teams to output file.
3. If AutoSched is specified then store parameters.
4. Using external program, sort the teams.
5. Re-read the teams and recreate 'Teams.df'.
6. Open 'Teams.df' for reading.
7. Extract data and store.
8. If no separator in it, then take it as a
team. Strip blanks and store.
9. Close input file.
10.IF AUTOMATIC - Read specified schedule file.
11.Read schedules and store dates/weeks.
12.Give error if the number of teams does not equal
the number of lines in the schedule file.
13.Write the dates/weeks to a file then use an
external program to sort them, writing back to the file.
14.Read dates into array and delete file.
15.Format dates array with season start date.
16.Format and write '.sf' files.
17.IF MANUAL - Open 'Teams.sf' file.
18.Write league name to it.
19.Loop and write all teams with a schedule of
all other teams. Number of matches is stored.
20.Close output file.
21.Open 'Teams.stats' for writing.
22.Write all data such as PLAYED,WIN,DRAW,LOST,GOALS_FOR,GOALS_AGAINST and
POINTS for each team.
23.Close file. Delete file (if found).
24.Create a report on the league created and then exit.
************************************************************************** */
PARSE ARG league_file
version = 2
league_file = "Data/" || strip(league_file)
input_file = '.df'
output_file = '.sf'
output2_file = '.stats'
output3_file = '.temp'
delput_file = '.sflearn'
title = '*LEAGUE_NAME='
points_win = '*POINTS_PER_WIN='
points_drw = '*POINTS_PER_DRW='
points_lse = '*POINTS_PER_LSE='
points_gls = '*POINTS_PER_GLS='
releg = '*RELEGATION='
playother = '*PLAY_OTHER='
promoted = '*PROMOTED='
num_divs = '*NUM_DIVISIONS='
divisions = '*DIVISIONS='
pkauthor = '* Author ='
pkversion = '* Version='
separator = '*'
teams. = '???'
tcount = 0
ttc = 0
ptsgls = 0
input2_file = '.schd'
separator = '*'
not_played = '__ __'
dateweeks. = '???'
tdateweeks. = '???'
schedules2. = '???'
schedules4. = '???'
schedules6. = '???'
schedules8. = '???'
schedules0. = '???'
autosched = "*AUTOSCHD="
autos = 0
ndivs = 0
promo = 0
divs = ''
oddnums = "1 3 5 7 9"
refdays = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" /* used for word positions */
if open(datafile,"Data/Football.locale",'r') then do
line = readln(datafile)
locdir = strip(line)
close(datafile)
end
else do
say
say "ERROR : (Scheduler)"
say
say "Cannot read 'Data/Football.locale' for the locale settings."
exit
end
dfordir = locdir"Football.locale_data"
locdir = locdir"Exec/Scheduler.data"
if open(datafile,"ENV:FootballRXPath",'r') then do
line = readln(datafile)
rxdir = strip(line)
close(datafile)
end
else
rxdir = "SYS:Rexxc/"
if exists(locdir) > 0 then do
address command rxdir'rx 'locdir
VarCount = getclip('VarCount')
do i = 1 to VarCount
interpret getclip('var.'i)
end
end
else do
say
say "ERROR : (Scheduler)"
say
say "Cannot find '"locdir"' to read locale settings."
exit
end
if exists(dfordir) > 0 then do
address command rxdir'rx 'dfordir
VarCount = getclip('VarCount')
do i = 1 to VarCount
interpret getclip('var.'i)
end
end
else do
say
say "ERROR : (Scheduler)"
say
say "Cannot find '"dfordir"' to read date locale settings."
exit
end
if exists(league_file || input_file) = 0 then do
say
say s_error
say
say s_t1"'"league_file||input_file"'."
exit
end
tcount = 0
if open(datafile,league_file || input_file,'r') then do
if open(datafile2,league_file || output3_file,'w') then do
do while ~eof(datafile)
line = readln(datafile)
line = strip(line)
if pos(separator,line) > 0 & line ~='' then do
if pos(autosched,line) > 0 then do
autofile = delstr(line,1,10)
autos = 1
end
tcount = tcount + 1
teams.tcount = line
end
else do
ttc = ttc + 1
writeln(datafile2,line)
end
end
close(datafile2)
end
else do
say
say s_error
say
say s_t2"'"league_file||output3_file"'."
close(datafile)
exit
end
close(datafile)
end
else do
say
say s_error
say
say s_t3"'"league_file || input_file"'"s_t4
exit
end
address command 'sort 'league_file || output3_file league_file || output3_file
if open(datafile2,league_file || output3_file,'r') then do
if open(datafile,league_file || input_file,'w') then do
do i=1 to tcount
if teams.i ~= '' then
writeln(datafile,teams.i)
end
do j=1 to ttc /* while ~eof(datafile2) */
line = readln(datafile2)
line = strip(line)
if line ~= '' then do
if j = ttc then
writech(datafile,line)
else
writeln(datafile,line)
end
end
close(datafile)
end
else do
say
say s_error
say
say s_t2"'"league_file||input_file"'."
close(datafile2)
exit
end
close(datafile2)
end
else do
say
say s_error
say
say s_t3"'"league_file || output3_file"'"s_t4
exit
end
address command 'delete >NIL: 'league_file || output3_file
tcount = 0
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(title,line) > 0 then league_title = delstr(line,1,13)
if pos(pkauthor,line) > 0 then author = delstr(line,1,12)
if pos(pkversion,line) > 0 then fversion = delstr(line,1,12)
if pos(points_win,line) > 0 then ptswin=delstr(line,1,16)
if pos(points_drw,line) > 0 then ptsdrw=delstr(line,1,16)
if pos(points_lse,line) > 0 then ptslse=delstr(line,1,16)
if pos(points_gls,line) > 0 then ptsgls=delstr(line,1,16)
if pos(releg,line) > 0 then reg = delstr(line,1,12)
if pos(playother,line) > 0 then playo = delstr(line,1,12)
if pos(promoted,line) > 0 then promo = delstr(line,1,10)
if pos(num_divs,line) > 0 then ndivs = delstr(line,1,15)
if pos(divisions,line) > 0 then divs = delstr(line,1,11)
if pos(separator,line) = 0 then do
line = strip(line)
tcount = tcount + 1
teams.tcount = line
end
end
close(datafile)
end
else do
say
say s_error
say
say s_t3"'"league_file || input_file"'."
exit
end
if ndivs > 1 then do
if words(divs)+1 ~= ndivs then do
say
say s_error
say
say s_t6
say s_t7
say s_t8
say s_t9
say s_t10
say
say s_t11
say " "words(divs)""s_t12""ndivs"."
say s_t13"'"words(divs)+1"'"s_14
say
say s_t15
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
fd = 0
do i=1 to ndivs-1
if exists("Data/"||word(divs,i)||input_file) = 0 then do
if fd = 0 then do
say
say s_error
say
end
say s_t18"'"word(divs,i)"'"s_t19
fd = fd + 1
end
end
if fd > 0 then do
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
end
/* Automatic Schedule creation */
if autos = 1 then do
if exists("Data/Schedules/"autofile||input2_file) = 0 then do
say
say s_error
say
say s_t1"'Data/Schedules/"autofile||input2_file"'."
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
ct = 0
sct2= 0
sct4= 0
sct6= 0
sct8= 0
sct0= 0
weeks = 0
dates = 0
sch = 1
if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do
mkct = ((tcount - 1) * playo) * (tcount/2)
kmct = 0
do while ~eof(datafile)
line = readln(datafile)
if line ~= '' & pos(separator,line) = 0 then do
counter = words(line)
do i=1 to counter
if word(line,i) ~= 0 then
kmct = kmct + 1
end
end
end
close(datafile)
end
else do
say
say s_error
say
say s_t1"'Data/Schedules/"autofile||input2_file"'"s_t5
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
mongoose = mkct / kmct
if mkct ~= kmct & pos(".",mongoose) > 0 then do
say
say s_error
say
say s_t20"'Data/Schedules/"autofile||input2_file"'"
say s_t21""tcount""s_t22
say playo""s_t23""kmct""s_t24""mkct""s_t25
say s_t26
say s_t27
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos("*WEEKS",line) then do
weeks=1
end
if pos("*DATES=",line) then do
startdate=substr(line,8,8)
dates = 1
end
if pos("*NEXT",line) > 0 then sch = sch + 1
if line ~= '' & pos(separator,line) = 0 then do
if sch = 1 then do
sct2 = sct2 + 1
schedules2.sct2 = line
end
if sch = 2 then do
sct4 = sct4 + 1
schedules4.sct4 = line
end
if sch = 3 then do
sct6 = sct6 + 1
schedules6.sct6 = line
end
if sch = 4 then do
sct8 = sct8 + 1
schedules8.sct8 = line
end
if sch = 5 then do
sct0 = sct0 + 1
schedules0.sct0 = line
end
counter = words(line)
do i=1 to counter
sdate = word(line,i)
if sdate = 0 then
iterate
if ct = 0 then do
ct = ct + 1
dateweeks.ct = sdate
end
else do
ij = 0
do j=1 to ct
if sdate = dateweeks.j then do
ij = 1
leave
end
end
if ij = 0 then do
ct = ct + 1
dateweeks.ct = sdate
end
end
end
end
end
close(datafile)
end
else do
say
say s_error
say
say s_t1"'Data/Schedules/"autofile||input2_file"'"s_t5
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
sct = (sct2 + sct4 + sct6 + sct8 + sct0) / sch
if counter ~= sct then do
say
say s_error
say
say s_t28""sct""s_t29
say s_t30""counter""s_t31
say
say s_t32
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
if open(datafile2,"RAM:schd.temp",'w') then do
do j=1 to ct
writeln(datafile2,dateweeks.j)
end
close(datafile2)
end
else do
say
say s_error
say
say s_t33
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
if weeks = 1 then
address command 'sort RAM:schd.temp RAM:schd.temp'
if dates = 1 then
address command 'Exec/SortWkDts'
if open(datafile2,"RAM:schd.temp",'r') then do
do j=1 to ct
dateweeks.j = readln(datafile2)
end
close(datafile2)
end
else do
say
say s_error
say
say s_t34
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
address command 'delete >NIL: RAM:schd.temp'
if dates = 1 then do
do j=1 to ct
if dateweeks.j = startdate then do
do i=1 to j-1
tdateweeks.i = dateweeks.i
end
k = 1
do i=j to ct
dateweeks.k = dateweeks.i
k = k + 1
end
do i=1 to j-1
dateweeks.k = tdateweeks.i
k = k + 1
end
leave
end
end
end
if open(outfile,league_file || output_file,"w") then do
writeln(outfile,"*")
writeln(outfile,"**" league_title)
writeln(outfile,"*")
writeln(outfile,"*")
matches = 0
do i=1 to ct
if weeks = 1 then
writeln(outfile,"*Week: "dateweeks.i)
if dates = 1 then do
mnth = substr(dateweeks.i,3,2)
ndate= substr(dateweeks.i,5,4)||mnth||substr(dateweeks.i,1,2)
weekd= date('w',ndate,'s')
do kw=1 to 7
if weekd = word(refdays,kw) then do
weekd = word(days,kw)
leave
end
end
parse var date_format "day" sp1 "number" sp2 "month" sp3 "year" .
/* DATE */
writeln(outfile,"*Date: "weekd||sp1||substr(dateweeks.i,1,2)||sp2||word(months,mnth)||sp3||substr(dateweeks.i,5,4))
end
writeln(outfile,"*")
do k=1 to counter
do j=1 to counter
do l=1 to sch
if l=1 then sdate = word(schedules2.k,j)
if l=2 then sdate = word(schedules4.k,j)
if l=3 then sdate = word(schedules6.k,j)
if l=4 then sdate = word(schedules8.k,j)
if l=5 then sdate = word(schedules0.k,j)
if dateweeks.i = sdate then do
writech(outfile,left(teams.k,30))
writeln(outfile," __ __ " teams.j)
matches = matches + 1
leave
end
end
end
end
writeln(outfile,"*")
end
writeln(outfile,"*")
close(outfile)
end
else do
say
say s_error
say
say s_t2"'"league_file || output_file"'."
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
end
/* Manual Schedule creation */
if autos = 0 then do
if open(outfile,league_file || output_file,"w") then do
writeln(outfile,"*")
writeln(outfile,"**" league_title)
writeln(outfile,"*")
writeln(outfile,"*")
plyo = playo /* this handles playing odd times each team */
if pos(playo,oddnums) > 0 then
plyo = plyo + 1
increm = plyo / 2
matches = 0
do k=1 to increm
do i=1 to tcount
do j=1 to tcount
if j~=i then do
writech(outfile,left(teams.i,30))
writeln(outfile," __ __ " teams.j)
matches = matches + 1
end
end
writeln(outfile,"*")
if i ~= tcount then
writeln(outfile,"*")
end
end
writech(outfile,"*")
close(outfile)
end
else do
say
say s_error
say
say s_t2"'"league_file || output_file"'."
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
end
if exists(league_file||output2_file) = 0 then do
if open(outfile,league_file || output2_file,"w") then do
writeln(outfile,title""league_title)
do i=1 to tcount
writeln(outfile,"*TEAM="teams.i)
writeln(outfile,"*PLY=0")
writeln(outfile,"*WIN=0")
writeln(outfile,"*DRW=0")
writeln(outfile,"*LST=0")
writeln(outfile,"*GOF=0")
writeln(outfile,"*GOA=0")
if i = tcount then
writech(outfile,"*PTS=0")
else
writeln(outfile,"*PTS=0")
end
close(outfile)
end
else do
say
say s_error
say
say s_t2"'"league_file || output2_file"'."
say
say
say s_t16"'"league_file || input_file"'"s_t17
exit
end
end
/* create report */
select
when playo = 2 then playo = s_t58
otherwise
playo = playo" "s_t56
end
/* ..and after all files have been created, lets clear up any previous... */
if exists(league_file||delput_file) > 0 then
address command 'c:Delete >NIL: 'league_file||delput_file
say
say center(s_t35"'"league_title"'",78)
say "-------------------------------------------------------------------------------"
say " "s_t36""date('e')""s_t37""time()
say
say s_t38""author
say s_t39""fversion
say "_______________________________________________________________________________"
say
say s_t40""tcount" "s_t41""matches
say
say s_t42""ptswin" "s_t57". "s_t43""reg
say s_t44""ptsdrw" "s_t57". "s_t45""playo
say s_t46""ptslse" "s_t57". "s_t47""ptsgls
say " "s_t48""promo
say
say s_t49""ndivs" "s_t50
say s_t51""divs
say
if autos = 1 then do
say s_t52"'"autofile||input2_file"'."
say
end
/*
if matches > 999 then
say "* "s_t53" *"
*/
say "_______________________________________________________________________________"
say
say s_t54
say s_t55
say
do i=1 to tcount
say teams.i
end
say
say "-------------------------------------------------------------------------------"
say
exit